package com.yulebaby.callsenter.utils;

import com.google.gson.Gson;
import com.yulebaby.callsenter.bean.CallLogBean;
import com.yulebaby.callsenter.bean.CustomerBean;
import com.yulebaby.callsenter.ui.base.BaseBean;

import java.lang.reflect.Type;
import java.util.List;


/**
 * Author: Zhangbo
 * Time: 2016年11月9日
 */
public class GsonUtil {

    private GsonUtil() {
    }

    public static <T> T parseJsonToBean(String json, Class<T> cls) {

        Gson gson = new Gson();
        T t = null;
            try {
            t = gson.fromJson(json, cls);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return t;
    }

    /**
     * new TypeToken<List<LoginBean>>() {}.getType()
     *
     * @param json
     * @param type
     * @return
     */
    public static List<?> parseJsonToList(String json, Type type) {
        Gson gson = new Gson();
        List<?> list = gson.fromJson(json, type);
        return list;
    }

    /**
     * 将bean转换为json
     *
     * @param bean
     * @return
     */
    public static String parseBeanToJson(BaseBean bean) {
        return new Gson().toJson(bean);
    }
}
